﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
using STT.Business;
using STT.Entities;
using STT.Layer.Connection;
using System.Data;

namespace STT.Admin.UserControls
{
    public partial class ucThongKeHocVien : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Methods.ChucVu(ref ddChucVu);
            Methods.DonViHocVien(ref ddDonVi);
            Methods.KhoaHoc(ref ddKhoaHoc);
            Methods.Lop(ref ddLop);
            Methods.HocHam(ref ddHocHam);
            Methods.HocVi(ref ddHocVi);
        }

        protected void btTimKiem_Click(object sender, EventArgs e)
        {
            LoadData();
        }

        void LoadData()
        {
            DataTable dt = BTbHocVien.StatisticsStudentByCourses(new ETbHocVien
            {
                ChucVu = int.Parse(ddChucVu.SelectedValue.Trim()),
                MaDonVi = int.Parse(ddDonVi.SelectedValue.ToString()),
                MaLop = int.Parse(ddLop.SelectedValue.ToString()),
                HocHam = ddHocHam.SelectedValue,
                HocVi = ddHocVi.SelectedValue
            }, ddKhoaHoc.SelectedValue.ToString(), Session["TenDN"].ToString(), txtTuoi.Text);
            rpvHocVien.Visible = true;
            rpvHocVien.LocalReport.ReportPath = "RDLC\\TKeHocVien.rdlc";
            rpvHocVien.LocalReport.DataSources.Clear();
            rpvHocVien.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dt));
            //Response.Write(Session["TenDN"].ToString());
        }

        protected void gvHocVien_DataBound(object sender, EventArgs e)
        {
            GridView gv1 = (GridView)sender;
            gv1.ShowFooter = true;

            if (gv1.Rows.Count > 0)
            {
                for (int i = gv1.Columns.Count - 1; i >= 1; i += -1)
                {
                    gv1.FooterRow.Cells.RemoveAt(i);

                }

                gv1.FooterRow.Cells[0].ColumnSpan = gv1.Columns.Count;

                gv1.FooterRow.Cells[0].HorizontalAlign =

                HorizontalAlign.Center;
                gv1.FooterRow.Cells[0].Text =

                "Tổng số kết quả tìm thấy: " + gv1.Rows.Count.ToString();
                gv1.FooterRow.Cells[0].Font.Bold = true;
            }
        }
    }
}